import mCommon from '@/components/mCommon/index';
import { useRef } from 'react';
/*  */
const FormCommon = () => {
  const mFormRef = useRef();
  const FormConfig = {
    colNum: 4,
    cols: [
      {
        formKey: 'name',
        type: 'input',
        label: '名称',
      },
      {
        formKey: 'home',
        type: 'input',
        label: '地址',
      },
      {
        formKey: 'status',
        type: 'select',
        label: '状态',
        propsConfig: {
          list: [
            { label: '启用', value: 1 },
            { label: '未启用', value: 0 },
          ],
        },
      },
      {
        formKey: 'home1',
        type: 'input',
        label: '地址',
      },
      {
        type: 'btns',
        handleClick: (type) => {
          console.log('1', type);
        },
        propsConfig: {
          groupType: 'search',
        },
      },
    ],
  };
  const getForm = (data) => {
    console.log('data', data);
    console.log('mFormRef', mFormRef);
  };
  let nestData = [
    {
      label: '浙江省',
      value: 'zhejiang',
      children: [
        {
          label: '杭州市',
          value: 'hangzhou',
          children: [
            {
              label: '滨江区',
              value: 'binjiang',
              children: [
                {
                  label: 'hhhh',
                  value: 'xxxx',
                },
              ],
            },
            {
              label: '江干区',
              value: 'jianggan',
            },
          ],
        },
        {
          label: '宁波市',
          value: 'ningbo',
          children: [
            {
              label: '余姚市',
              value: 'yuyao',
            },
          ],
        },
        {
          label: '绍兴市',
          value: 'shaoxing',
        },
      ],
    },
  ];
  function TreeToArrayFor(tree) {
    if (!Array.isArray(tree) || !tree.length) throw new Error('请传入数组');
    for (let i = 0; i < tree.length; i++) {
      if (tree[i].children) {
        tree = tree.concat(tree[i].children);
      }
      delete tree[i].children;
    }
    return tree;
  }
  console.log('TreeToArrayFor(nestData)', TreeToArrayFor(nestData));
  return (
    <>
      {/* <mCommon.Micon type="icon-gengduo"></mCommon.Micon> */}
      {/* <mCommon.Minput></mCommon.Minput>
      <mCommon.Mselect options={options}></mCommon.Mselect>
      <mCommon.MbtnList></mCommon.MbtnList> */}
      <mCommon.Mform
        cRef={mFormRef}
        FormConfig={FormConfig}
        getForm={getForm}
      ></mCommon.Mform>
    </>
  );
};
export default FormCommon;
